package com.at.c02_classloader.load;

import sun.misc.Launcher;
import sun.security.ec.CurveDB;

import java.net.URL;
import java.security.Provider;

/**
 * @author huangchao E-mail:fengquan8866@163.com
 * @version 创建时间：2024/6/23 8:32
 */
public class ClassLoaderTest1 {
    public static void main(String[] args) {
        System.out.println("********启动类加载器*********");
        // 获取 BootstrapClassLoader 能够加载api的路径
        URL[] urLs = Launcher.getBootstrapClassPath().getURLs();
        for (URL urL : urLs) {
            System.out.println(urL.toExternalForm());
            // file:/D:/Program%20Files/Java/jdk1.8.0_121/jre/lib/resources.jar
            // file:/D:/Program%20Files/Java/jdk1.8.0_121/jre/lib/rt.jar
            // file:/D:/Program%20Files/Java/jdk1.8.0_121/jre/lib/sunrsasign.jar
            // file:/D:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jsse.jar
            // file:/D:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jce.jar
            // file:/D:/Program%20Files/Java/jdk1.8.0_121/jre/lib/charsets.jar
            // file:/D:/Program%20Files/Java/jdk1.8.0_121/jre/lib/jfr.jar
            // file:/D:/Program%20Files/Java/jdk1.8.0_121/jre/classes
        }
        // 从上面的路径中随意选择一个类，来看看它的类加载器是什么：
        ClassLoader classLoader = Provider.class.getClassLoader();
        System.out.println(classLoader); // null

        System.out.println("********扩展类加载器*********");
        String extDirs = System.getProperty("java.ext.dirs");
        for (String path : extDirs.split(";")) {
            System.out.println(path);
            // D:\Program Files\Java\jdk1.8.0_121\jre\lib\ext
            // C:\Windows\Sun\Java\lib\ext
        }
        // 从上面的路径中随意选择一个类，来看看它的类加载器是什么：
        ClassLoader classLoader1 = CurveDB.class.getClassLoader();
        System.out.println(classLoader1); // sun.misc.Launcher$ExtClassLoader@29453f44
    }
}
